;(function(){
	'use strict';
	angular.module('services.analysisSysOM.cleanCount')
	.factory('finishSuccessRateService',finishSuccessRateService);
	function finishSuccessRateService(Restangular,CtrlShowAndHide,cleanCountService,CoreService,CoreLoading){
		return {
			search: search
		};
		function getFinishSuccessRate(params,callback){
			Restangular.all('sas/analysisSysOM/cleanCount/queryFinishSuccessRate').post(params).then(callback);
		}
		function search(sendData){
			var flag = CtrlShowAndHide.flag;
			flag.state = !flag.state;
			var send = {
				time: CoreService.dateFormat(sendData.time, 'yyyy-MM-dd')
			};
			if(!flag.state){
				CoreLoading.setState(true);
				flag.show = 'view';
				send.title = cleanCountService.getTimeTitle(send,'first')+'清结算系统业务处理一次完成结算成功率';
				getFinishSuccessRate(send,function(result){
					if(result.state === '10000' && result.data.length >= 1){
						var myEcharts = echarts.init(document.getElementById('doc'));
						flag.items = result.data;
						flag.title = send.title;
						var option = cleanCountService.getEchartsInstance(result,flag.title,'ccBusinessName','finishSuccessRate','一次完成结算成功率','bar');
						option.grid = {x2:150};
						option.tooltip = {
							show:true,
							formatter: function(params){
								return params.name+'<br/>'+params.seriesName+': '+params.value+'%';
							}
						};
						myEcharts.setOption(option);
						cleanCountService.exportView(send,flag,myEcharts);
						flag.arrow = true;
					}else if(result.data.length === 0){
						flag.state = true;
						flag.arrow = false;
						CoreService.dialog('查询无数据');
					}else {
						flag.state = true;
						flag.arrow = false;
						CoreService.dialog('查询错误');
					}
					CoreLoading.setState(false);
				});
			}
		}
	}
})();